package chai.ningning.address;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

public class InetAddressTest2 {

    public static void main(String[] args) throws UnknownHostException {

        String hostname = "DESKTOP-QUF3J7K";

        //getAllByName(hostname) 根据名称 或 IP地址 获得全部IP地址，名称
        InetAddress[] addressArray = InetAddress.getAllByName(hostname);

        System.out.println(Arrays.toString(addressArray));

        for (int i = 0; i < addressArray.length; i++) {
            InetAddress address = addressArray[i];
            String hostAddress = address.getHostName();
            byte[] addr = address.getAddress();
            System.out.println( hostAddress + " : " + Arrays.toString( addr ) + " , " + addr.length );
        }
    }

}
